<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../js/vue.js"></script>

    <style>
        .grid {
            margin: 100px auto;
            width: 1000px;
            text-align: center;
        }

        .grid table {
            width: 100%;
            border-collapse: collapse;
        }

        .grid th {
            background-color: orange;

        }

        .grid th,td {
            border: 1px solid orange;
            height: 35px;
            line-height: 35px;

        }

        .grid .dept_input {
            margin-bottom: 5px;
            padding-top: 15px;
            background-color: pink;

        }
    </style>


</head>
<body>
<div id="div1">
   <div class="grid">
    <h2>部门管理</h2>
    <div class="dept_input">
        <div>
            编号：
            <input type="text" id="id1" v-model="id">
            名称：
            <input type="text" id="name1" v-model="name">
            <button @click="handle">保存</button>
        </div>
    </div>
       <table>
           <tr>
               <th>部门编号</th>
               <th>部门名称</th>
               <th>创建时间</th>
               <th>操作</th>
           </tr>

               <!--遍历数据-->
                <tr v-for="item in departments">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.date}}</td>
                    <td>
                        <a href="">修改</a>
                        <span>|</span>
                        <a href="">删除</a>
                    </td>
                </tr>

       </table>
   </div>

</div>

<script>
    /*
      动态处理响应式数据

    */
    const vueObj = new Vue({
        el: '#div1',
        data: {
            id: "",
            name: "",

            departments: [
                {
                id: 1,
                name: "采购部",
                date: "2022-02-12",
                },
                {
                    id: 2,
                    name: "销售部",
                    date: "2022-02-12",
                },
                {
                    id: 3,
                    name: "技术部",
                    date: "2022-02-12",
                },
                {
                    id: 4,
                    name: "摸鱼部",
                    date: "2022-02-12",
                },

                ]

        },
        methods:{
            handle: function () {
                // console.log("添加");
                const dept = {};   //创建一个对象
                dept.id = this.id;
                dept.name = this.name;
                dept.date = new Date();
                this.departments.push(dept);
                this.id = '';
                this.name = '';
            },
        }

    });




</script>
</body>
</html>
